<!-- 倒计时  -->
<template>
  <view class="time">
    <view class="time-content">
      <view class="number">{{ time_ | time2str(1) }}</view>
      <view class="text">天</view>
      <view class="number">{{ time_ | time2str(2) }}</view>
      <view class="text">小时</view>
      <view class="number">{{ time_ | time2str(3) }}</view>
      <view class="text">分钟</view>
      <view class="number">{{ time_ | time2str(4) }}</view>
      <view class="text">秒</view>
    </view>
  </view>
</template>

<script>
let timer;
export default {
  props: {
    time: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      time_: this.time
    };
  },
  mounted() {
    timer = setInterval(() => {
      this.time_--;
      if (this.time_ <= 0) {
        clearInterval(timer);
        this.$emit("event-end");
      }
    }, 1000);
  }
};
</script>

<style lang="scss" scoped>
.time {
  &-content {
    background-color: #e41c10;
    color: #ffffff;
    min-width: 600upx;
    padding: 20upx 40upx;
    border-radius: 50upx;
    display: inline-flex;
    justify-content: center;
    align-items: flex-end;
  }

  text-align: center;
  margin: 10upx auto;

  view {
    margin: 0 5upx;
  }
  .number {
    font-size: 50upx;
    line-height: 40upx;
  }
  .text {
    font-size: 28upx;
  }
}
</style>
